<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<%@ include file="/static/admin/jsp/include.jsp"%>

	<script type="text/javascript">
        var grid;
        var index;

        var addFun = function($dialog, $grid, $pjq) {
            var dialog = parent.sy.modalDialog({
                title : '新增元素',
                width : 800,
                height : 600,
                url : sy.contextPath + '/go?path=chemical/chemicalAdd',
                buttons : [ {
                    text : '保存',
                    handler : function() {
                        dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                    }
                } ]
            });
        };

        var editFun = function($dialog, $grid, $pjq) {
            var rows = grid.datagrid('getSelections');
            if (rows.length != 1) {
                parent.$.messager.w('请选择一条记录进行编辑！');
                return;
            }
            var dialog = parent.sy.modalDialog({
                title : '修改',
                width : 800,
                height : 600,
                //url : sy.contextPath + '/go?path=goods/goodsEdit&id=' + rows[0].id,
                url : sy.contextPath + '/go?path=chemical/chemicalEdit&id=' + rows[0].id,
                buttons : [ {
                    text : '保存',
                    handler : function() {
                        dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                    }
                } ]
            });
        };

        function getConNum (id){
            var url = sy.contextPath + '/goods/getConNum';
            $.post(url, {id : id}, function() {
                grid.datagrid('reload');
            }, 'json');
		}

        $(function() {
            grid = $('#grid').datagrid({
                url : sy.contextPath + '/chemicalType/list',
                singleSelect : true,
                frozenColumns : [ [ {
                    width : '100',
                    checkbox:true,
                    field : 'id',
                    align : 'center'
                }] ],
                columns : [ [ {
                    width : $(this).width() * 0.05,
                    title : '元素中文名',
                    field : 'name',
                    align : 'center',
                },{
                    width : $(this).width() * 0.05,
                    title : '元素中文名',
                    field : 'type',
                    align : 'center',
					formatter : function (v,r,i) {
						if(v == 1){
						    return '阴阳型';
						}else if(v == 2){
						    return '数值型';
						}
                    }
				},{
                    width : $(this).width() * 0.05,
                    title : '元素符号',
                    field : 'chemicalName',
                    align : 'center',
                },{
                    width : $(this).width() * 0.08,
                    title : '释义简介',
                    field : 'infoBegin',
                    align : 'center'
                },{
                    width : $(this).width() * 0.08,
                    title : '释义',
                    field : 'info',
                    align : 'center',
					formatter : function(v,r,i){
                        return '<a href="javascript:void(0);" onclick="checkInfo(\''+r.id+'\')" class="button button-info" title="查看释义">查看释义</a>'
					}
				},{
                    width : $(this).width() * 0.05,
                    title : '参考范围',
                    field : 'range',
                    align : 'center',
					formatter : function(v,r,i){

                        if(r.type == 1){
                            //阴阳型
                            //return r.rangeInfo;
							if(r.rangeInfo == 1){
							    return '阳'
							}else if(r.rangeInfo == 2){
                                return '阴'
							}
                        }else if(r.type == 2){
                            //数值型
                            return r.rangeMin+'-'+r.rangeMax+'('+r.rangeInfo+')';
                        }
					}
                }, {
                    width : $(this).width() * 0.08,
                    title : '结果分析',
                    field : 'rangUpInfo',
                    align : 'center',
                    formatter : function(v,r,i){
                        //return '<a href="javascript:void(0);" onclick="addRangUpInfoV2(\''+r.id+'\')" class="button button-info" title="查看结果分析">查看结果分析</a>'
                        return '<a href="javascript:void(0);" onclick="addRangUpInfoV3(\''+r.id+'\')" class="button button-info" title="查看结果分析">查看结果分析</a>'
					}
                },
//					{
//                    width : $(this).width() * 0.08,
//                    title : '横坐标跨度',
//                    field : 'xAxis',
//                    align : 'center',
//                    formatter : function(v,r,i){
//                        return '<a href="javascript:void(0);" onclick="addxAxis(\''+r.id+'\')" class="button button-info" title="横坐标跨度">横坐标跨度</a>'
//                    }
//                },
//					{
//                    width : $(this).width() * 0.08,
//                    title : '纵坐标跨度',
//                    field : 'yAxis',
//                    align : 'center',
//                    formatter : function(v,r,i){
//                        return '<a href="javascript:void(0);" onclick="addyAxis(\''+r.id+'\')" class="button button-info" title="纵坐标跨度">纵坐标跨度</a>'
//                    }
//                },
					{
                    width : $(this).width() * 0.12,
                    title : '查看参数',
                    field : 'param',
                    align : 'center',
                    formatter : function(v,r,i){
                        console.log(v)
                        //if(v == null || v == ''){
                            return '<a href="javascript:void(0);" onclick="editParam(\''+r.id+'\',\''+r.type+'\')" class="button button-info" title="查看参数">查看参数</a><a href="javascript:void(0);" onclick="editParamV2(\''+r.id+'\',\''+r.type+'\')" class="button button-warning" title="重新填写">重新填写</a>'
						//}

                        //return '<a href="javascript:void(0);" onclick="editParamV2(\''+r.id+'\')" class="button button-warning" title="重新填写">重新填写</a>'
                    }
                },
//					{
//					width : $(this).width() * 0.08,
//					title : '查看字典',
//					field : 'dicMsg',
//					align : 'center',
//					formatter : function(v,r,i) {
//                        return '<a href="javascript:void(0);" onclick="editDic(\'' + r.id + '\')" class="button button-info" title="查看字典">查看字典</a>'
//                    }
//				},
					{
                        width : $(this).width() * 0.05,
                        title : '查看二维码',
                        field : 'qrImg',
                        align : 'center',
                        formatter: function(v, r, i) {
                            if (v != null && v != '') {
                                return po.showImg(v, 20, 20);
                            } else {
                                return null;
                            }
                        }
                 },{
                        width : $(this).width() * 0.05,
                        title : '预览',
                        field : 'show',
                        align : 'center',
                        formatter : function(v,r,i) {
                            return '<a href="javascript:void(0);" onclick="show(\'' + r.id + '\')" class="button button-info" title="预览">预览</a>'
                            //return'<a href="https://cli.im/" target="_blank"  class="button button-info" title="预览">预览</a>'
                        }
                 },{
                    width : $(this).width() * 0.08,
                    title : '创建时间',
                    field : 'createTime',
                    align : 'center',
                }
                ] ]
            });
        });

        function SaveData(data) {
            var url = sy.contextPath + '/chemicalType/save';
            $.post(url, data, function() {
                grid.datagrid('reload');
            }, 'json');
        }

        /**
		 * 暂时不用
         * @param id
         */
        function addRangUpInfo(id){
            var dialog = parent.sy.modalDialog({
                title : '结果分析',
                width : 800,
                height : 600,
                url : sy.contextPath + '/go?path=chemical/resultInfoEdit&id='+id,
                buttons : [ {
                    text : '保存',
                    handler : function() {
                        dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                    }
                } ]
            });
		}

        /**
		 * 暂时不用
         * @param id
         */
		function addRangUpInfoV2(id){
            var dialog = parent.sy.modalDialog({
                title : '结果分析',
                width : 800,
                height : 600,
                url : sy.contextPath + '/go?path=chemical/resultInfoEditV2&id='+id,
                buttons : [ {
                    text : '保存',
                    handler : function() {
                        dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                    }
                } ]
            });
		}

        function addRangUpInfoV3(id){
            var dialog = parent.sy.modalDialog({
                title : '结果分析',
                width : 800,
                height : 600,
                url : sy.contextPath + '/go?path=chemical/resultInfoEditV3&id='+id,
                buttons : [ {
                    text : '保存',
                    handler : function() {
                        dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                    }
                } ]
            });
        }


		function addxAxis (id) {
            var dialog = parent.sy.modalDialog({
                title : '横坐标跨度',
                width : 800,
                height : 600,
                url : sy.contextPath + '/go?path=chemical/axis/xAxisEdit&id='+id,
                buttons : [ {
                    text : '保存',
                    handler : function() {
                        dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                    }
                } ]
            });
        }

        function addyAxis (id) {
            var dialog = parent.sy.modalDialog({
                title : '纵坐标',
                width : 800,
                height : 600,
                url : sy.contextPath + '/go?path=chemical/axis/yAxisEdit&id='+id,
                buttons : [ {
                    text : '保存',
                    handler : function() {
                        dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                    }
                } ]
            });
        }


        function editParam(id,type) {
            if(type == 1){
                var dialog = parent.sy.modalDialog({
                    title : '配置参数',
                    width : 800,
                    height : 600,
                    url : sy.contextPath + '/go?path=chemical/param/yyparamEdit&id='+id,
                    buttons : [ {
                        text : '保存',
                        handler : function() {
                            dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                        }
                    } ]
                });
			}else{
                var dialog = parent.sy.modalDialog({
                    title : '配置参数',
                    width : 800,
                    height : 600,
                    url : sy.contextPath + '/go?path=chemical/param/paramEdit&id='+id,
                    buttons : [ {
                        text : '保存',
                        handler : function() {
                            dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                        }
                    } ]
                });
			}

        }

        function editParamV2(id,type) {
            if(type == 1){
                var dialog = parent.sy.modalDialog({
                    title : '配置参数',
                    width : 800,
                    height : 600,
                    url : sy.contextPath + '/go?path=chemical/param/yyparamEditV2&id='+id,
                    buttons : [ {
                        text : '保存',
                        handler : function() {
                            dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                        }
                    } ]
                });
            }else{
                var dialog = parent.sy.modalDialog({
                    title : '配置参数',
                    width : 800,
                    height : 600,
                    url : sy.contextPath + '/go?path=chemical/param/paramEditV2&id='+id,
                    buttons : [ {
                        text : '保存',
                        handler : function() {
                            dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                        }
                    } ]
                });
            }
        }

        function editDic(id) {
            var dialog = parent.sy.modalDialog({
                title : '配置字典',
                width : 800,
                height : 600,
                url : sy.contextPath + '/go?path=chemical/dic/editDic&id='+id,
            });
        }

        function checkInfo(id) {
            var dialog = parent.sy.modalDialog({
                title : '查看释义',
                width : 800,
                height : 600,
                url : sy.contextPath + '/go?path=chemical/checkInfo&id='+id,
            });
        }

        function show(id) {
            var dialog = parent.sy.modalDialog({
                title : '预览',
                width : 800,
                height : 600,
                url : sy.contextPath + '/go?path=chemical/show&id='+id,
            });
        }
	</script>
</head>
<body>
<div id="toolbar">
	<form id="searchForm">
		<div>
			<input type="text" class="easyui-textbox" name="name" style="width: 150px" prompt="元素名称或英文名称"/>
		</select>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-search'" onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-search-minus'" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
		</div>
	</form>
	<div class="tbbutton">

		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-plus-circle',plain:true" onclick="addFun();">添加</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-pencil',plain:true" onclick="editFun();">修改</a>

		<%--<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-trash',plain:true" onclick="delFun();">删除</a>--%>

	</div>
</div>
<table id="grid" data-options="fit:true,border:false"></table>
</body>
</html>